<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('修改字段状态')" />
    <th:block th:include="include :: select2-css" />
</head>
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form class="form-horizontal m" id="form-fieldStatus-edit" th:object="${fieldStatus}">
            <input name="id" th:field="*{id}" type="hidden">
            <div class="form-group">    
                <label class="col-sm-3 control-label is-required">字段状态名称：</label>
                <div class="col-sm-8">
                    <input name="statusZhName" th:field="*{statusZhName}" class="form-control" type="text" required>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label is-required">字段状态英文名称：</label>
                <div class="col-sm-8">
                    <input name="statusEnName" th:field="*{statusEnName}" class="form-control" type="text" required>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">字段状态介绍：</label>
                <div class="col-sm-8">
                    <textarea name="description" class="form-control">[[*{description}]]</textarea>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">用于状态字段的场景模型：</label>
                <div class="col-sm-8">
                    <select name="sceneModel" class="form-control m-b" th:with="type=${@dict.getType('sceneModel')}">
                        <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}" th:field="*{sceneModel}"></option>
                    </select>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label is-required">字段：</label>
                <div class="col-sm-8">
                    <select id="fieldId" name="fieldId" class="form-control">

                    </select>
                </div>
            </div>
        </form>
    </div>
    <th:block th:include="include :: footer" />
    <th:block th:include="include :: select2-js" />
    <script th:inline="javascript">
        var prefix = ctx + "fieldStatus/fieldStatus";
        var fieldInfoList = [[${fieldList}]];
        var fieldId = [[${fieldStatus.fieldId}]];
        $("#form-fieldStatus-edit").validate({
            focusCleanup: true
        });

        function submitHandler() {
            if ($.validate.form()) {
                $.operate.save(prefix + "/edit", $('#form-fieldStatus-edit').serialize());
            }
        }

        $(function () {
            if (fieldInfoList && fieldInfoList.length > 0) {
                for (var i=0; i<fieldInfoList.length; i++) {
                    if (fieldId == fieldInfoList[i].id) {
                        $("#fieldId").append('<option value="'+fieldInfoList[i].id+'">'+fieldInfoList[i].fieldName + '('+fieldInfoList[i].tableName+' selected)</option>')
                    } else {
                        $("#fieldId").append('<option value="'+fieldInfoList[i].id+'">'+fieldInfoList[i].fieldName + '('+fieldInfoList[i].tableName+')</option>')
                    }
                }
                $("#fieldId").val(fieldId);
            }
        })
    </script>
</body>
</html>